package com.gnerv.pabu.basic.core.utils;

import com.gnerv.pabu.basic.core.entity.EmailConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class JavaMailSenderUtils {

    public static JavaMailSender build(EmailConfig emailConfig) {
        JavaMailSenderImpl sender = new JavaMailSenderImpl();
        sender.setHost(emailConfig.getHost());
        sender.setUsername(emailConfig.getAccount());
        sender.setPassword(emailConfig.getAuthCode());
        sender.setPort(emailConfig.getPort());
        return sender;
    }

}
